package org.example;

import org.apache.commons.cli.*;
import org.dcm4che3.data.Attributes;
import org.dcm4che3.image.ICCProfile;
import org.dcm4che3.imageio.plugins.dcm.DicomImageReadParam;
import org.dcm4che3.io.DicomInputStream;
import org.dcm4che3.tool.common.CLIUtils;
import org.dcm4che3.util.SafeClose;

import javax.imageio.*;
import javax.imageio.stream.FileImageInputStream;
import javax.imageio.stream.FileImageOutputStream;
import javax.imageio.stream.ImageInputStream;
import java.awt.image.BufferedImage;
import java.awt.image.Raster;
import java.io.File;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.text.MessageFormat;
import java.util.*;
import java.util.function.Predicate;
import java.util.stream.StreamSupport;

public class Main2 {
    public void getImageReader() {
        try {
            String p = "/Users/zhouyang/Documents/dcm_data/MR443845/1.2.840.113619.2.475.5554020.7716616.27179.1629717979.971.dcm";
            Iterator iter = ImageIO.getImageReadersByFormatName("DICOM");
            ImageReader reader = (ImageReader) iter.next();
            DicomImageReadParam param = (DicomImageReadParam) reader.getDefaultReadParam();
            Raster raster = reader.readRaster(0, param);
            ImageInputStream iis = ImageIO.createImageInputStream(new File(p));
            System.out.println("bbbb");
            reader.setInput(iis, false);
            System.out.println("cccc");
            int frames = reader.getNumImages(true);
            System.out.println(frames);
        } catch (IOException ie) {
            ie.printStackTrace();
        }

    }

    public static void main(String[] args) {
        Main2 main2 = new Main2();
        main2.getImageReader();
    }
}